//
//  WebVController.swift
//  XNavigator_Example
//
//  Created by x on 2024/9/1.
//  Copyright © 2024 CocoaPods. All rights reserved.
//

import UIKit
import WebKit

class WebViewController: UIViewController {

    var url: URL?
    lazy var webView: WKWebView = {
        let view = WKWebView()
        view.navigationDelegate = self
        view.uiDelegate = self
        view.frame = view.bounds
        return view
    }()
    init() {
        super.init(nibName: nil, bundle: nil)
        view.backgroundColor = .white
        url = nil
    }
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    override func viewDidLoad() {
        super.viewDidLoad()
        view.addSubview(webView)
        // Do any additional setup after loading the view.
    }

    func load(url: URL) {
        self.url = url
        webView.load(URLRequest(url: url))
    }
}

extension WebViewController: WKNavigationDelegate {

    func webView(_ webView: WKWebView, didCommit navigation: WKNavigation!) {
//        self.url = webView.url ?? ""
    }

    func webView(_ webView: WKWebView, didFinish navigation: WKNavigation!) {
    }

    func webView(_ webView: WKWebView, didFail navigation: WKNavigation!, withError error: Error) {
    }
}

extension WebViewController: WKUIDelegate {

}

